package com.lianniu.web.product.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.alibaba.fastjson.JSON;
import com.lianniu.web.base.BaseResult;
import com.lianniu.web.pagination.PaginationInfo;
import com.lianniu.web.product.model.ProductCateVo;
import com.lianniu.web.product.service.IProductCateService;

@Controller
@RequestMapping("/rest/productCate")
public class ProductCateRestController {
	
	private final static Logger logger = Logger.getLogger(ProductCateRestController.class);
	  
	
	  @Autowired
	  private IProductCateService productCateService;
	  
	  @RequestMapping(value="/productCateList",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult productCateList(HttpServletRequest request, ProductCateVo curVo, PaginationInfo paginationInfo)
	  {
	       logger.info("ProductCateRestController  productCateList begin.");
	       try {
	           
	           logger.info("productCateList begin.");          
	           BaseResult baseResult = productCateService.selectByProductCateForPage(curVo, paginationInfo);
	           logger.info("productCateList end.");
	           logger.info("ProductCateRestController productCateList end.");
	           return baseResult;
	       } catch (Exception e) {
	       logger.error("ProductCateRestController productCateList error:" + e.getMessage());
	       logger.error("ProductCateRestController productCateList end.");
	       return BaseResult.exception(e.getMessage());
	     }
	  }
	  
	  @RequestMapping(value="/selectProductCateById",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectProductCateById(HttpServletRequest request,ProductCateVo curVo) {
	        logger.info("ProductCateRestController selectProductCateById begin.");
	        try {
	                    
	          BaseResult baseResult = productCateService.selectById(curVo);
	          logger.info("selectDictionaryById end.");
	          logger.info("ProductCateRestController selectProductCateById end.");
	          return baseResult;
	        } catch (Exception e) {
	          logger.error("ProductCateRestController selectProductCateById error:" + e.getMessage());
	          logger.error("ProductCateRestController selectProductCateById end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  } 
	  
	  @RequestMapping(value="/selectParentCate",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectParentCate(HttpServletRequest request) {
	        logger.info("ProductCateRestController selectParentCate begin.");
	        try {
	                    
	          BaseResult baseResult = productCateService.selectParentCate();
	          logger.info("selectParentCate end.");
	          logger.info("ProductCateRestController selectParentCate end.");
	          return baseResult;
	        } catch (Exception e) {
	          logger.error("ProductCateRestController selectParentCate error:" + e.getMessage());
	          logger.error("ProductCateRestController selectParentCate end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  } 
	  
	  @RequestMapping(value="/selectChildCateKv",method={RequestMethod.GET,RequestMethod.POST})
	  public @ResponseBody BaseResult selectChildCateKv(HttpServletRequest request) {
	        logger.info("ProductCateRestController selectChildCateKv begin.");	        
	        String cateId = request.getParameter("cateId");
	        logger.info("ProductCateRestController selectChildCateKv cateId:" + JSON.toJSONString(cateId));
	        try {	                    
	          BaseResult baseResult = productCateService.selectChildCateKV(cateId);
	          logger.info("selectChildCateKv end.");
	          logger.info("ProductCateRestController selectChildCateKv end.");
	          return baseResult;
	        } catch (Exception e) {
	          logger.error("ProductCateRestController selectChildCateKv error:" + e.getMessage());
	          logger.error("ProductCateRestController selectChildCateKv end.");
	          return BaseResult.exception(e.getMessage());
	        }
	  } 

}
